package com.lyn.serialPort;

import java.io.File;
import java.io.FileDescriptor;

public class SerialPort {
    public boolean chmod777(File file) {
        if (null != file && file.exists()) {
            try {
                Process su = Runtime.getRuntime().exec("/system/bin/su");
                String cmd = "chmod 666 " + file.getAbsolutePath() + "\nexit\n";
                su.getOutputStream().write(cmd.getBytes());
                if (0 == su.waitFor() && file.canRead() && file.canWrite() && file.canExecute()) {
                    return true;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return false;
        }
        return false;
    }

    public native FileDescriptor open(String path, int baudRate, int flags);

    public native void close();

    static {
        System.loadLibrary("SerialPort");
    }
}
